<template>
  <div class="news-info-container">
    <!-- 标题 -->
    <h1 class="title">{{newsinfo.title}}</h1>
    <!-- 子标题 -->
    <p class="subtitle">
      <span>{{newsinfo.add_time | dataFormat}}</span>
      <span>点击{{newsinfo.click}}次</span>
    </p>
    <hr />
    <!-- 内容 -->
    <div class="content" v-html="newsinfo.content"></div>
    <!-- 评论区 -->
    <comment :id="this.id"></comment>
  </div>
</template>
<script>
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      //将url传递的id通过路由拿过来
      id: this.$route.params.id,
      newsinfo: {}
    };
  },
  methods: {
    getNewsInfo() {
      // <!-- vue-router上restful风格路由获取id -->
      this.$http.get("getnew/" + this.id).then(result => {
        this.newsinfo = result.body.message[0];
        console.log(result);
      });
    }
  },
  components: {
    comment
  },
  created() {
    this.getNewsInfo();
  }
};
</script>

<style lang="scss">
.news-info-container {
  padding: 0 5px;
  .title {
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
    color: red;
  }
  .subtitle {
    font-size: 14px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .content {
  }
}
</style>